﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class EditorUtilityDemo : EditorWindow
{
    float secs = 10.0f;
    double startval = 0;
    double progress = 0;
    bool isShow;
    [MenuItem("Tools/EditorUtilityDemo")]
    static void Init()
    {
        var window = GetWindow(typeof(EditorUtilityDemo));
        window.Show();
    }

    private void OnGUI()
    {
        secs = EditorGUILayout.FloatField("Time to wait :", secs);

        if (GUILayout.Button("Display button"))
        {
            startval = EditorApplication.timeSinceStartup;
            isShow = !isShow;
        }

        if (GUILayout.Button("Clear Button"))
        {
            EditorUtility.ClearProgressBar();
        }

        if (progress<secs&&isShow == true)
        {
            EditorUtility.DisplayProgressBar("Simple display bar", "show a progress bar fot the given second", (float)(progress / secs));
        }
        else
        {
            startval = EditorApplication.timeSinceStartup;
            progress = 0.0f;
            return;
        }
        progress = EditorApplication.timeSinceStartup - startval;
    }

    private void OnInspectorUpdate()
    {
        Repaint();
    }
}
